package com.qianfeng.ssm.pojo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.ToString;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

@Data
@ToString
@JsonInclude(JsonInclude.Include.NON_EMPTY)//空的数据就不会返回
public class TbUser implements CheckNull {

    private Long id;
    private String username;
    private String password;
    private String email;
    private String gender;
    private Long flag;
    private Long role;
    private String code;

    @Override
    public boolean isEmpty(CheckType type) {
        switch (type) {
            case ADD:
                return !StringUtils.hasText(email) || !StringUtils.hasText(password) || !StringUtils.hasText(gender) || !StringUtils.hasText(username);
            case UPDATE:
                return (ObjectUtils.isEmpty(id) || id <= 0) || (!StringUtils.hasText(email)
                        && !StringUtils.hasText(password)
                        && !StringUtils.hasText(gender)
                        && !StringUtils.hasText(code)
                        && ObjectUtils.isEmpty(flag)
                        && ObjectUtils.isEmpty(role));
        }
        return false;
    }
}
